package com.warm.base.jdk.grammar;

/**
 * @Date: 2020/4/9 13:47
 * @Author: LChuang
 * @Description: 位运算符
 */
public class OperatorTest {

    /**
     * << # 带符号左移
     *
     * <<< # 无符号左移
     *
     * |= # 两个二进制对应位都为 0 时, 结果为0, 否则为 1
     *     a = 5(0000 0101), b = 3(0000 0011); --> a |= b --> (0000 0111)
     *
     * &= # 两个二进制对应位都为 1 时, 结果为1, 否则为 0
     *
     * ^= # 两个二进制对应位相同时, 结果为0, 否则结果为 1
     */

    public static void main(String[] args) {
        //System.out.println(1 << 30);
        int n = 6;
        // 6 >>> 1  0000 0110 --> 0000 0011
        // 6 = 6 | 6 >>> 1  --> 0000 0110  0000 0011 --> 0000 0111 = 7
        n = n | n >>> 1;
        System.out.println(n);
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        System.out.println(n);
    }
}
